import axios from "axios";
class HttpRequest {
  /**
   * 初始化
   * @param {*} baseUrl
   * @param {*} options
   */
  constructor(baseUrl = "", options) {
    this.baseUrl = baseUrl;
    this.options = options;
  }
  /**
   * 默认配置
   */
  defaulConfig() {
    return {
      baseURL: this.baseUrl,
      withCredentials: false,
      headers: {
        //
      },
    };
  }
  /**
   * 实例化
   */
  instance() {
    const reqeustConfigs = Object.assign(this.defaulConfig(), this.options);
    return axios.create(reqeustConfigs);
  }

  /**
   * 获取axios实例
   * @param {*} baseUrl
   * @param {*} options
   */
  static getInstance(baseUrl = "", options = {}) {
    return new HttpRequest(baseUrl, options).instance();
  }
}

export default HttpRequest;
